package com.yilin.platform.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yilin.platform.base_core.application.PageData;
import com.yilin.platform.base_core.tools.QueryUtil;
import com.yilin.platform.entity.system.Jurisdiction;
import com.yilin.platform.mapper.system.JurisdictionMapper;
import com.yilin.platform.service.system.IJurisdictionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 权限service
 *
 * @author lx
 * @date 2024/6/2 14.32
 */
@Service
@Transactional()
public class JurisdictionService extends ServiceImpl<JurisdictionMapper, Jurisdiction> implements IJurisdictionService {

    @Resource
    private JurisdictionMapper jurisdictionMapper;


    @Override
    public void saveJurisdiction(Jurisdiction jurisdiction) {
        jurisdiction.setCreateTime(new Date());
        jurisdictionMapper.insert(jurisdiction);
    }
    @Override
    public PageData<Jurisdiction> getJurisdictionPage(Jurisdiction query, Integer page, Integer limit) {
     QueryWrapper<Jurisdiction> queryWrapper=new QueryWrapper<>();
        QueryUtil.andQueryWrapper(queryWrapper,query);
        return  jurisdictionMapper.selectPage(new PageData<>(page,limit),queryWrapper);
    }
    @Override
    public List<Jurisdiction> getJurisdictionList() {
        return jurisdictionMapper.selectList(null);
    }

    @Override
    public Jurisdiction getJurisdictionById(String jurisdictionId) {
        return jurisdictionMapper.selectById(jurisdictionId);
    }
    @Override
    public List<Jurisdiction> getJurisdictionListByIds(String[] ids) {
        QueryWrapper<Jurisdiction> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("id",Arrays.asList(ids));
        return jurisdictionMapper.selectList(queryWrapper);
    }


    @Override
    public void editJurisdiction(Jurisdiction jurisdiction) {
        jurisdictionMapper.updateById(jurisdiction);
    }

    @Override
    public int removeJurisdiction(String[] jurisdictionIds) {
        return  jurisdictionMapper.deleteBatchIds(Arrays.asList(jurisdictionIds));
    }
}
